package org.example.file;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

public class GetLastModifiedTime {
    public static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    public static final String FILE_PATH = "/home/johnconnor/software/firefox/application.ini";
    public static void main(String[] args) throws IOException {
        Path path = Paths.get(FILE_PATH);
        BasicFileAttributes attr = Files.readAttributes(path,BasicFileAttributes.class);
        System.err.println("lastModifiedTime:" + attr.lastModifiedTime());
        FileTime fileTime = attr.lastModifiedTime();
        LocalDateTime localDateTime = fileTime.toInstant()
                .atZone(ZoneId.systemDefault())
                .toLocalDateTime();
        String formatTime = localDateTime.format(DATE_FORMATTER);
        System.err.println("lastModifiedTime:" + formatTime);
    }
}
